package com.isfto.dao;


import com.github.pagehelper.Page;
import com.isfto.entity.tablepojo.FlightChange;
import com.isfto.entity.tablepojo.Tickets;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface FlightChangeOutDao {
    /**
     * 插入出港航班申请
     * @param flightChange
     * @return
     */
    @Insert("insert into flightchangeout(cfno,startapcd,startfptt,endapcd,endfplt,name,email,changereason,flid) " +
            "values(#{cfno},#{startapcd},#{startfptt},#{endapcd},#{endfplt},#{name},#{email},#{changereason},#{flid})")
    int saveInfo(FlightChange flightChange);

    /**
     * 修改审核状态
     */
    @Update("update flightchangeOut set status=#{status} where cfno=#{cfno} and startapcd=#{startapcd} and endapcd=#{endapcd} and startfptt=#{startfptt} and endfplt=#{endfplt}")
    int updateStauts(FlightChange flightChange);
    /**
     * 条件查询数据
     * @param cfno
     * @param startapcd
     * @param endapcd
     * @return
     */
    @Select("select * from flightchangeOut where cfno=#{cfno} and startapcd=#{startapcd} and endapcd=#{endapcd} and startfptt=#{startfptt} and endfplt=#{endfplt}")
    FlightChange afterInfoOut(@Param("cfno") String cfno, @Param("startapcd") String startapcd, @Param("endapcd") String endapcd,@Param("startfptt")String startfptt,@Param("endfplt")String endfplt);
    /**
     * 查询出港航班申请纪律
     * @param page
     * @param pageSize
     * @return
     */
    @Select("select * from flightchangeout limit #{page},#{pageSize}")
    List<FlightChange> flightChange(Integer page, Integer pageSize);

    /**
     * 查询出港航班总记录数
     * @return
     */
    @Select("select count(*) from flightchangeout")
    int total();

    /**
     * 出港条件查询数据
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @return
     */
    @Select(" select * from flightchangeout where startapcd=#{startapcd} and endapcd=#{endapcd} and startfptt>=#{startfptt} and endfplt<=#{endfplt} limit #{page},#{pageSize}")
    List<FlightChange> flightChangeInfoOUt(@Param("startapcd") String startapcd, @Param("endapcd") String endapcd,@Param("startfptt") String startfptt,@Param("endfplt") String endfplt,@Param("page")Integer page,@Param("pageSize")Integer pageSize);

    /**
     * 出港符合条件总个数
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @return
     */
    @Select(" select count(*) from flightchangeout where startapcd=#{startapcd} and endapcd=#{endapcd} and startfptt>=#{startfptt} and endfplt<=#{endfplt}")
    Integer flightChangeCountOUt(@Param("startapcd") String startapcd, @Param("endapcd") String endapcd,@Param("startfptt") String startfptt,@Param("endfplt") String endfplt);

    /**
     * 查询延误航班的fide
     * @param flid
     * @return
     */
    @Select("select fide from showtables where flid=#{flid} group by fide")
    String fideInfo(String flid);

    /**
     * 增加表中延误标记
     * @param abrs
     * @param fide
     * @return
     */
    @Update("update dfoe_dfdl_dflt set abst=#{abst},abrs=#{abrs} where fide=#{fide}")
    int upAbst(@Param("abrs") String abrs,@Param("abst") String abst,@Param("fide") String fide);

    /**
     * 更改实际到达时间
     * @param frtt
     * @param fide
     * @return
     */
    @Update("update dfme_frtt set frtt=#{frtt} where fide=#{fide}")
    int upfrtt(@Param("frtt") String frtt,@Param("fide") String fide);

    @Update("update flightchangeout set endfplt=#{endfplt} where flid=#{flid} and cfno=#{cfno}")
    int upFlightChange(@Param("endfplt") String endfplt,@Param("flid") String flid,@Param("cfno") String cfno);
    @Select( "select *from tickets where status =#{status} " )
    Page<Tickets> pageQuery(Integer status);

    @Update( "update tickets set status=#{status} where id = #{id}" )
    Boolean updateTickets(@Param( "id" ) Integer id,@Param( "status" ) Integer status);

    @Insert("insert into flightchangeout(cfno,startapcd,startfptt,endapcd,endfplt,name,email,changereason,flid,status) " +
            "values(#{cfno},#{startapcd},#{startfptt},#{endapcd},#{endfplt},#{name},#{email},#{changereason},#{flid},#{status})")
    Boolean insert(FlightChange flightChange);
}
